/* 引入mobx  action:动作  observable：装饰器  （useObservable:使数据变为响应式）  */
import { observable, action } from 'mobx';

/* 引入获取所有展示接口api */
import { getConsumerList,getIdentifyList,getApiAuthority,getViewAuthority,getIdentityApiAuthorityRelation,getIdentityViewAuthorityRelation } from '../service/index';

export default class Consumer{
    [key: string]: any

    /* 展示用户列表 */
    @observable
    consumerList = [];
    /* 展示身份列表 */
    @observable
    identifyList = [];
    /* 接口权限列表 */
    @observable
    apiAuthorityList = [];
    /* 视图权限列表 */
    @observable
    viewAuthorityList = [];
    /* 身份和api权限列表 */
    @observable
    identityApiAuthorityRelation = [];
    /* 身份和视图权限列表 */
    @observable
    identityViewAuthorityRelation = [];

    /* 获取展示用户数据 */
    @action
    async getConsumerListAction(){
        /* 发送请求 */
        let result = await getConsumerList();
        /* console.log('getConsumerListAction...',result); */
        
        /* 判断 */
        if (result.data){
            this.consumerList = result.data.data;
        }
    };

    /* 获取身份方法 */
    @action
    async getIdentifyListAction(){
        let result = await getIdentifyList();
       /*  console.log('getIdentifyListAction...',result); */

        if (result.data){
            this.identifyList = result.data.data;
        }
    };

    /* 获取接口权限方法 */
    @action
    async getApiAuthorityAction(){
        let result = await getApiAuthority();
        /* console.log(result.data); */
        
        if (result.data){
            this.apiAuthorityList = result.data.data;
        }
    };

    /* 获取视图权限方法 */
    @action
    async getViewAuthorityAction(){
        let result = await getViewAuthority();
        /* console.log(result.data); */
        if (result.data){
            this.viewAuthorityList = result.data.data;
        }
    };

    /* 获取身体和权限关系方法 */
    @action
    async getIdentityApiAuthorityRelationAction(){
        let result = await getIdentityApiAuthorityRelation();
        /* console.log(result.data); */
        if (result.data){
            this.identityApiAuthorityRelation = result.data.data;
        }
    };

    /* 获取身份和视图权限方法 */
    @action
    async getIdentityViewAuthorityRelationAction(){
        let result = await getIdentityViewAuthorityRelation();
        /* console.log(result.data); */
        if (result.data){
            this.identityViewAuthorityRelation = result.data.data;
        }
    }
}
